<template>
  <erp-modal
    :loading="loading"
    :width="size"
    :title="title"
    height="100%"
    :visible="visible"
    :position="positionCom"
    :transfer="true"
    @close="handleClose"
  >
    <template #default>
      <div
        v-loading="loading"
        class="erp-drawer-container"
        element-loading-text="页面初始化中..."
        element-loading-spinner="el-icon-loading"
      >
        <div class="erp-drawer-body">
          <slot name="default" />
        </div>
      </div>
    </template>
    <template
      v-if="showFooter"
      #footer
    >
      <slot name="footer" />
    </template>
  </erp-modal>
</template>

<script>
import ErpModal from '@/components/erp/ErpModal/ErpModal';
/**
 * 表单抽屉弹窗
 * @author maolin
 */
export default {
  name: "ErpDrawer",
  components: {
    ErpModal
  },
  props: {
    /**
     * 是否加载中
     * @public
     */
    loading: {
      type: Boolean,
      default: false
    },
    /**
     * 是否显示关闭按钮
     * @public
     */
    showClose: {
      type: Boolean,
      default: false
    },
    /**
     * 是否显示
     * @public
     */
    visible: {
      type: Boolean,
      default: false
    },
    /**
     * 是否显示底部区域
     * @public
     */
    showFooter: {
      type: Boolean,
      default: true
    },
    /**
     * 弹窗宽度
     * @public
     */
    size: {
      type: [String, Number],
      default () {
        return '500px';
      }
    },
    /**
     * 弹窗标题
     * @public
     */
    title: {
      type: String,
      default: ''
    },
  },
  data () {
    return {

    };
  },
  computed: {
    positionCom () {
      let width = this.size;
      let widthNum = width;
      if (!isNaN(width)) {
        widthNum += 'px';
      }
      return {
        top: 0,
        left: 'calc(100% - ' + widthNum + ')',
      };
    }
  },
  methods: {
    /**
     * 通知父组件关闭弹窗
     * @public
     */
    handleClose () {
      /**
       * 通知父组件关闭弹窗
       * @public
       */
      this.$emit('close');
    }
  }
};
</script>

<style lang="scss" scoped>
$primaryColor: var(--primary-color);
    .erp-drawer-container{
        height: 100%;
        background-color: #fff;
        .erp-drawer-header{
            box-sizing: border-box;
            margin: 0 50px;
            height: 60px;
            line-height: 60px;
            font-size: 16px;
            color: #092C4C;
            font-weight: bold;
            border-bottom: 1px solid #E6E9EE;
            .icon-close{
                float: right;
                line-height: 60px;
                font-size: 10px;
                color: #5A6875;
                font-weight: normal;
            }
        }
        .erp-drawer-body{
            padding: 20px 0;
            width: 100%;
            height: calc(100vh - 128px);
            overflow: auto;
        }
        .erp-drawer-footer {
            padding: 0 50px;
            height: 68px;
            background-color: #F6F7F9;
            position: relative;
            .erp-drawer-footer-buttons{
                position: absolute;
                right: 50px;
                top: 50%;
                transform: translateY(-50%);
            }
        }
    }
</style>
